package com.bobo.base.config;

import com.baomidou.mybatisplus.autoconfigure.DdlApplicationRunner;
import com.baomidou.mybatisplus.extension.ddl.IDdl;
import com.bobo.ApiApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 生成war包使用外部Tomcat启动时注入启动类
 *
 * @author LILIBO
 * @since 2021-06-24
 */
@Configuration
public class ServletInitializer extends SpringBootServletInitializer {

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ApiApplication.class);
    }

    /**
     * 解决SpringBoot3.2.1集成启动报错：org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'ddlApplicationRunner' is expected to be of type 'org.springframework.boot.Runner' but was actually of type 'org.springframework.beans.factory.support.NullBean'
     *
     * @param ddlList
     * @return
     */
    @Bean
    public DdlApplicationRunner ddlApplicationRunner(List<IDdl> ddlList) {
        return new DdlApplicationRunner(ddlList);
    }

}
